package com.zhilong.selenium.web;

import com.zhilong.selenium.component.PurchaseBrowserDriver;
import com.zhilong.selenium.entity.ChromePurchase;
import com.zhilong.selenium.service.ChromeRushPurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@RequestMapping
@Controller
public class WebController {

    @Autowired
    ChromeRushPurchaseService chromeRushPurchaseService;

    @ResponseBody
    @RequestMapping(value = "/rush2buy")
    public ResponseEntity result(@ModelAttribute("chromePurchase")ChromePurchase chromePurchase){
        String message = chromeRushPurchaseService.rush2Purchase(chromePurchase);
        return ResponseEntity.ok(message);
    }

    @ResponseBody
    @RequestMapping("/openbrowser")
    public ResponseEntity openBrowser(){
        chromeRushPurchaseService.gotologinPage();
        return ResponseEntity.ok("浏览器打开成功");
    }

    @ResponseBody
    @RequestMapping("/closebrowser")
    public ResponseEntity closeBrowser(){
        PurchaseBrowserDriver.close();
        return ResponseEntity.ok("浏览器关闭成功");
    }

    @GetMapping(value = "/index")
    public String index(){
        return "index";
    }
}
